package object;

import help.Utility;

import java.util.ArrayList;

import dto.ScoreDTO;

public class TestObject {
	
	private int titleIndex;
	private int questionIndex;
	private int answerIndex;
	private ArrayList<Boolean> answers;
	
	public TestObject() {
		super();
	}
	public TestObject(int iTitleIndex, int iQuestionIndex) {
		super();
		this.titleIndex = iTitleIndex;
		this.questionIndex = iQuestionIndex;
		this.answerIndex = -1;
		answers = new ArrayList<Boolean>();
		for (int i = 0; i < 5; i++) {
			answers.add(false);
		}
	}
	
	public void setAnswerIndex(int value) {
		answers.set(value, true);
		this.answerIndex = value;
	}
	
	public String getQuestion() {
		return Utility.lstTitleDTO.get(titleIndex).lstQuestion.get(questionIndex).getContent();
	}
	
	public int getAnswerIndex() {
		return this.answerIndex;
	}
	
	public int getNoAnswer() {
		return Utility.lstTitleDTO.get(titleIndex).getAnswerSize();
	}
	
	public int getScore() {
		if (answerIndex < 0) {
			return 0;
		}
		else {
			int noAnswer = getNoAnswer();
			int maxAnswer = 5;
			int answerID = getAnswerIDAtPosition(answerIndex + noAnswer - maxAnswer);
			for (ScoreDTO score : Utility.lstTitleDTO.get(titleIndex).lstQuestion.get(questionIndex).lstScore) {
				if (score.getAnswerID() == answerID) {
					return score.getScore();
				}
			}
			return 0;
		}
	}

	public int getAnswerIDAtPosition(int position) {
		return Utility.lstTitleDTO.get(titleIndex).lstAnswer.get(position).getID();
	}
	
	public ArrayList<Boolean> getAnswers() {
		return answers;
	}
	public void setAnswers(ArrayList<Boolean> answers) {
		this.answers = answers;
	}
	public int getQuestionID() {
		return Utility.lstTitleDTO.get(titleIndex).lstQuestion.get(questionIndex).getID();
	}
	public int getAnswerID() {
		int noAnswer = getNoAnswer();
		int maxAnswer = 5;
		return getAnswerIDAtPosition(answerIndex + noAnswer - maxAnswer);
	}
}
